/*
 * @Description  : 
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2022-02-22 13:53:29
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-02-28 15:56:46
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\order-management\\modal\\vehicle\\cancel-confirm\\cancel-confirm.component.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */
import { Component, OnInit, ViewChild } from '@angular/core';
import {
  SFComponent,
  SFCustomWidgetSchema,
  SFNumberWidgetSchema,
  SFRadioWidgetSchema,
  SFSchema,
  SFTextareaWidgetSchema,
  SFUISchema
} from '@delon/form';
import { _HttpClient } from '@delon/theme';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal';
import { OrderManagementService } from '../../../services/order-management.service';


@Component({
  selector: 'app-order-management-cancel-confirm',
  templateUrl: './cancel-confirm.component.html'
})
export class OneCarOrderCancelConfirmComponent implements OnInit {
  i: any;     // 单行数据
  sts: any;   // 区分大宗、整车
  index: any; // 项目数
  ATTPrice: any; // 附加费
  List: any;    // 运费
  @ViewChild('sf', { static: false }) sf!: SFComponent;
  schema: SFSchema = {};
  ui: SFUISchema = {};
  constructor(
    private modalRef: NzModalRef,
    private modal: NzModalService,
    private msgSrv: NzMessageService,
    public service: OrderManagementService
  ) {}

  ngOnInit(): void {
    console.log(this.i);
    this.initSF();
    this.initData()
  
  }
  initSF() {
    this.schema = {
      properties: {
        reason: {
          type: 'string',
          title: '备注',
          maxLength: 50,
          ui: {
            widget: 'textarea',
            autosize: { minRows: 6, maxRows: 6 }
          } as SFTextareaWidgetSchema
        },
      },
      required: ['reason']
    };
    this.ui = {
      '*': {
        spanLabelFixed: 60,
        grid: { span: 20 }
      }
    };
  }
  initData() {
    let indexId = 0
    let index = 0
    let indexSurcharge = 0
    this.i?.mybidDetailInfo.forEach((ele: any) => {
      if(this.sts == 1) {
        // 大宗
        if (ele?.paymentStatusLabel == '已支付' && ele.expenseCode == "TRA") {
          index += ele?.price;
        }
        if (ele?.paymentStatusLabel == '已支付') {
          indexId += 1;
          indexSurcharge += ele?.surcharge;
        }
      } else {
        // 整车
        if (ele?.paymentStatusLabel == '已支付') {
          indexId += 1;
          index += ele?.price;
          indexSurcharge += ele?.surcharge;
        }
        console.log(ele.expenseCode)
      }
    });
    this.index = indexId
    this.List = index
    this.ATTPrice = indexSurcharge
    console.log(this.index)
    console.log(this.List)
  }
  save(value: any): void {
    if (!this.sf?.value.reason) {
      this.service.msgSrv.error('请填写备注信息！');
      return;
    }
    const params = { billId: this.i?.id, ...this.sf?.value };
    console.log(params)
    this.service.request(this.service.$api_billRefundApplication_save, params).subscribe(res => {
      if (res) {
        this.service.msgSrv.success('操作成功！');
        this.modalRef.close(true);
      } 
    });
  }

  close(value: boolean): void {
        this.modalRef.close(false);
  }
}
